// @Author EthanScriptOn
// @Desc
package util

import "time"

// DurationConvertTo Time conversion
func DurationConvertTo(d time.Duration, convertTo time.Duration) float64 {
	switch convertTo {
	case time.Nanosecond:
		return DurationToNanosecond(d)
	case time.Microsecond:
		return DurationToMicrosecond(d)
	case time.Millisecond:
		return DurationToMilliseconds(d)
	case time.Second:
		return DurationToSeconds(d)
	case time.Minute:
		return DurationToMinutes(d)
	case time.Hour:
		return DurationToHours(d)
	default:
		return 0
	}
}

func DurationToNanosecond(d time.Duration) float64 {
	return float64(d.Nanoseconds())
}

func DurationToMicrosecond(d time.Duration) float64 {
	return float64(d.Nanoseconds()) / float64(time.Microsecond.Nanoseconds())
}

func DurationToSeconds(d time.Duration) float64 {
	return float64(d.Nanoseconds()) / float64(time.Second.Nanoseconds())
}

func DurationToMilliseconds(d time.Duration) float64 {
	return float64(d.Nanoseconds()) / float64(time.Millisecond.Nanoseconds())
}

func DurationToMinutes(d time.Duration) float64 {
	return d.Minutes()
}

func DurationToHours(d time.Duration) float64 {
	return d.Hours()
}
